package view;

import controller.UserDetailsListener;
import pojo.User;

import javax.swing.*;
import java.awt.*;

public class UserDetails extends JDialog {
    private User user;
    JButton jButton1,jButton2,jButton3;
    JLabel labelId,labelName,labelGender,labelPN,labelType;
    //文本框
    JTextField tfId,tfNum,tfPN,tfName,tfGender,tfType,tfPW;
    private UserDetailsListener userDetailsListener;
    private SelfUserView selfUserView;
    private UserView userView;
    private JComboBox cBType;
    public UserDetails(User user, UserView userView){
        this.userView=userView;
        this.user=user;
        userDetailsListener =new UserDetailsListener(this,userView);
        this.setTitle("用户信息");
        this.setSize(400, 500);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setLayout(new BorderLayout());
        this.add(this.getPanel(),BorderLayout.CENTER);
        this.add(this.getButton(),BorderLayout.SOUTH);
    }

    public JPanel getPanel(){
        JPanel jPanel=new JPanel();

        jPanel.setLayout(new GridLayout(5, 2));
        labelId = new JLabel("                           学号:");
        labelName = new JLabel("                           姓名:");
        labelGender = new JLabel("                           年级:");
        labelPN = new JLabel("                           电话:");
        labelType=new JLabel("                           类别:");
        tfId= new JTextField(user.getUserId(),15);
        tfName = new JTextField(user.getUserName(),15);
        tfGender = new JTextField(user.getGender(),15);
        tfPN = new JTextField(user.getPhoneNumber(),15);
        cBType=new JComboBox();    //创建JComboBox
        cBType.addItem(user.getType());    //向下拉列表中添加一项
        cBType.addItem("系统管理员");
        cBType.addItem("图书管理员");
        cBType.addItem("普通用户");
        tfId.setEditable(false);
        jPanel.add(labelId);
        jPanel.add(tfId);

        jPanel.add(labelName);
        jPanel.add(tfName);

        jPanel.add(labelGender);
        jPanel.add(tfGender);

        jPanel.add(labelPN);
        jPanel.add(tfPN);

        jPanel.add(labelType);
        jPanel.add(cBType);

        return jPanel;
    }
    public JPanel getButton(){
        JPanel jPanel=new JPanel();
        jButton1=new JButton("修改");
        jButton2=new JButton("删除");
        jButton3=new JButton("返回");
        jPanel.add(jButton1);
        jPanel.add(jButton2);
        jPanel.add(jButton3);
        jButton1.addActionListener(userDetailsListener);
        jButton2.addActionListener(userDetailsListener);
        jButton3.addActionListener(userDetailsListener);
        return jPanel;
    }

    public User getUser() {
        return user;
    }

    public JTextField getTfNum() {
        return tfNum;
    }

    public JTextField getTfPN() {
        return tfPN;
    }

    public JTextField getTfName() {
        return tfName;
    }

    public JTextField getTfGender() {
        return tfGender;
    }

    public JTextField getTfType() {
        return tfType;
    }

    public JComboBox getCBType() {
        return cBType;
    }
}
